#include<bits/stdc++.h>
#include<cstdio>
using namespace std;

int T;
int n;
int maxn;
int N = 3e5;
int A[300000],C[300000],co[300000];

int getsum()
{
    int sum = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i-1;j>=1;j--)
        {
            if(co[i] == co[j])
            {
                if(A[i] == A[j]) C[i] = A[i];
                break;
            }
        }
        sum += C[i];
    }
    return sum;
}

void dfs(int now,int col)
{
    co[now] = col;
    if(now >= n)
    {
        maxn = max(maxn,getsum());
        return;
    }
    dfs(now+1,2);
    dfs(now+1,3);
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        maxn = 0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>A[i];
            C[i] = 0;
            co[i] = 0;
        }
        dfs(1,2);
        cout<<maxn<<"\n";
    }
    return 0;
}
